<?php

class ResumesController extends \BaseController {

	/**
	 * Display a listing of the resource.
	 * GET /resumes
	 *
	 * @return Response
	 */
	public function index()
	{
		$resumes = Resume::with('job')->orderBy('created_at', 'DESC');

		$get_gender = Input::get('gender', '');
		$get_education = Input::get('education', '');
		$get_experience = Input::get('experience', '');
		$get_job = Input::get('job', '');
		$get_status = Input::get('status', '');
		$get_marriage = Input::get('marriage');
        $get_expectation = Input::get('expectation');
        $get_restore_id = Input::get('restore_id');

		empty($get_gender)?:$resumes = $resumes->whereGender($get_gender);
		empty($get_education)?:$resumes = $resumes->whereEducation($get_education);
		empty($get_experience)?:$resumes = $resumes->whereExperience($get_experience);
		empty($get_job)?:$resumes = $resumes->whereJobId($get_job);
        empty($get_marriage)?:$resumes = $resumes->whereMarriage($get_marriage);
        empty($get_expectation)?:$resumes = $resumes->whereExpectation($get_expectation);
		empty($get_status)?:$resumes = $resumes->whereStatus($get_status);
		empty($get_restore_id)?:Resume::withTrashed()->where('id', $get_restore_id)->restore();

		$resumes = $resumes->paginate(15);

		$array_gender = [
			''  => '显示所有性别',
			'男' => '男',
			'女' => '女'
		];

		$array_education = [
			''   => '显示所有学历',
			'小学' => '小学',
			'初中' => '初中',
			'中专' => '中专',
			'高中' => '高中',
			'大专' => '大专',
			'本科' => '本科',
			'硕士' => '硕士',
			'博士' => '博士'
		];		

		$array_experience = [
			''   => '显示所有工作经验',
			'应届毕业生' => '应届毕业生',
			'1年以下' => '1年以下',
			'1-3年' => '1-3年',
			'3-5年' => '3-5年',
			'5-10年' => '5-10年',
			'10年以上' => '10年以上'
		];

		$array_status = [
			'' => '显示所有审核状态',
			'false' => '未审核',
			'1' => '已审核'
		];

        $array_marriage = [
            '' => '显示所有婚姻情况',
            '未婚' => '未婚',
            '已婚' => '已婚',
            '其他' => '其他'
        ];

        $array_expectation = [
            '' => '显示所有年薪期望',
            '3-5万' => '3-5万',
            '6-9万' => '6-9万',
            '10万以上' => '10万以上'
        ];

		$array_jobs = ['' => '显示所有职位申请'];
		$jobs = Job::get();

		foreach ($jobs as $job) {
			$array_jobs[$job->id] = $job->name; 
		}

		return View::make('resumes.index', compact('resumes', 
			'array_gender', 
			'array_education', 
			'array_experience', 
			'array_jobs',
			'array_status',
            'array_marriage',
            'array_expectation',
			'get_gender','get_education', 'get_experience', 'get_job', 'get_status', 'get_marriage', 'get_expectation'
			));
	}

	/**
	 * Display the specified resource.
	 * GET /resumes/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		$resume = Resume::with('job')->find($id);

		if( !$resume )
		{
			return Redirect::route('admin.resumes.index')->with('error', '对不起，没找相关的简历');
		}

		return View::make('resumes.show', compact('resume'));
	}


	/**
	 * Update the specified resource in storage.
	 * PUT /resumes/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		$resume = Resume::find($id);

		if( !$resume )
		{
			return Redirect::route('admin.resumes.index')->with('error', '对不起，没找到相关的简历');
		}

		$resume->status ? $resume->status = false : $resume->status = true;

		$resume->update();

		return View::make('resumes.show', compact('resume'))->with('message', '修改成功');
	}

	/**
	 * Remove the specified resource from storage.
	 * DELETE /resumes/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		$resume = Resume::find($id);

		if( !$resume )
		{
			return Redirect::route('admin.resumes.index')->with('error', '对不起，没找到相关的简历');
		}

		$resume->delete();

		return Redirect::route('admin.resumes.index')->with('message', '删除成功。<a href="?restore_id='.$resume->id.'">点击这里撤销删除</a>');

	}

}